﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ATM_Software
{
    class ATM
    {
        static void Main(string[] args)
        {
            while (true)
	        {
                Console.Clear();
                Console.ResetColor();
                Console.WriteLine("\n\t\t\t\tATM SOFTWARE");
                Console.WriteLine("\t\t\t===========================\n");
                Console.Write("Enter Login : ");
                Console.ForegroundColor = ConsoleColor.Green;
                string login  = Console.ReadLine();
                Console.ResetColor();
                Console.Write("Enter Pin Code : ");
                Console.ForegroundColor = ConsoleColor.Green;
                int pin = 0;
                try
                {
                    pin = int.Parse(Console.ReadLine());
                }
                catch(Exception)
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("Error : Please enter integer valued pin code with length 5 ...");
                    Console.Write("Press any key to re login ...");
                    Console.ReadKey();
                    Console.ResetColor();
                    continue;
                }
                Console.ResetColor();               
                CustomerManager manager = new CustomerManager();
                string choice = "";
                if (login.Equals("admin") && pin == 123)
                {
                    while (true)
                    {
                        Console.Clear();
                        Console.ResetColor();
                        Console.WriteLine("\n\t\t\t\tATM SOFTWARE");
                        Console.WriteLine("\t\t\t===========================\n");
                        Console.Write("User : ");
                        Console.ForegroundColor = ConsoleColor.Green;
                        Console.Write("Admin\n\n");
                        Console.ResetColor();
                        Console.WriteLine("1----Create New Account");
                        Console.WriteLine("2----Delete Existing Account");
                        Console.WriteLine("3----Update Account Information");
                        Console.WriteLine("4----Search for Account");
                        Console.WriteLine("5----View Reports");
                        Console.WriteLine("6----Exit\n");                        
                        Console.Write("Please select one of the above options : ");
                        Console.ForegroundColor = ConsoleColor.Green;
                        choice = Console.ReadLine();
                        Console.ResetColor();
                        if (choice.Equals("1"))
                        {
                            manager.CreateAccount();
                        }
                        else if (choice.Equals("2"))
                        {
                            manager.DeleteAccount();
                        }
                        else if (choice.Equals("3"))
                        {
                            manager.UpdateAccount();
                        }
                        else if (choice.Equals("4"))
                        {
                            manager.Search();
                        }
                        else if (choice.Equals("5"))
                        {
                            manager.ViewReports();
                        }
                        else if (choice.Equals("6"))
                        {
                            Console.WriteLine();
                            break;
                        }
                    }
                }
                else
                {
                    TransactionManager transactionManager = new TransactionManager();
                    CustomerData customer = new CustomerData();
                    customer.Login = login;
                    customer.PinCode = pin;
                    if (manager.Login(ref customer))
                    {
                        
                        while (true)
                        {
                            Console.Clear();
                            Console.ResetColor();
                            Console.WriteLine("\n\t\t\t\tATM SOFTWARE");
                            Console.WriteLine("\t\t\t===========================\n");
                            Console.Write("User : ");
                            Console.ForegroundColor = ConsoleColor.Green;
                            Console.Write(customer.Name + "\n\n");
                            Console.ResetColor();                            
                            Console.WriteLine("1----Withdraw Cash");
                            Console.WriteLine("2----Cash Transfer");
                            Console.WriteLine("3----Deposit Cash");
                            Console.WriteLine("4----Display Balance");
                            Console.WriteLine("5----Exit\n");
                           
                            Console.Write("Please select one of the above options : ");                            
                            Console.ForegroundColor = ConsoleColor.Green;
                            choice = Console.ReadLine();
                            Console.ResetColor();
                            if (choice.Equals("1"))
                            {
                                transactionManager.WithDraw(customer);
                                customer.EncryptDecrypt();                             
                            }
                            else if (choice.Equals("2"))
                            {
                                transactionManager.TransferCash(customer);
                                customer.EncryptDecrypt();
                            }
                            else if (choice.Equals("3"))
                            {
                                transactionManager.Deposit(customer);
                                customer.EncryptDecrypt();
                            }
                            else if (choice.Equals("4"))
                            {
                                manager.DisplayBalance(customer);
                            }
                            else if (choice.Equals("5"))
                            {
                                Console.WriteLine();
                                break;
                            }
                        }
                    }
                }
            }
        }
    }
}
